package topo;

import util.IdNumberFactory;

public class Edge {
	protected String label;
	private Node from;
	private Node to;
	private int cost;

	public String toString() {
		return cost + ":[" + getFrom().toString() + "] -> ["
				+ getTo().toString() + "]";
	}

	public Edge(Node from, Node to) {
		this.from = from;
		this.to = to;
		label = String.valueOf(IdNumberFactory.getId());
	}

	public Edge copy(Node fromState, Node toState) {
		Edge copiedSTF;
		try {
			copiedSTF = (Edge) getClass().newInstance();
		} catch (Throwable e) {
			System.err.println("Warning: clone of automaton failed!");
			return null;
		}
		copiedSTF.setFrom(fromState);
		copiedSTF.setTo(toState);
		copiedSTF.setCost(cost);
		copiedSTF.setLabel(label);

		return copiedSTF;
	}

	public Node getNodeOtherThan(Node node) {
		if (node == from)
			return to;
		else
			return from;
	}

	public Node getFrom() {
		return from;
	}

	public void setFrom(Node from) {
		this.from = from;
	}

	public Node getTo() {
		return to;
	}

	public void setTo(Node to) {
		this.to = to;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public int getCost() {
		return cost;
	}

	public void setCost(int cost) {
		this.cost = cost;
	}

}
